<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <#include "/pubHeadStyleTree.html">
    <script src="${ctx}/formStatic/form/CommonDialog.js" type="text/javascript" ></script>
</head>
<body>
<div class="formPreview layui-form">
 
</div>
<script>
    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'setter','ice','form','element','layer','slider','colorpicker','form','table','totalFilter','propsHandle'], function () {


    // -----常量声明----------
    var $ = layui.$,
    setter = layui.setter,  // 配置信息
    layer = layui.layer,
    ice = layui.ice,
    propsHandle = layui.propsHandle,
    form = layui.form,
    formId = '${formDefId}' || '',
    defProps = {
        //viewMould: 'form/formDef/view/formDesign/moulds/', // 组件模块 存放文件 *****
        viewMould: 'moulds/', // 组件模块 存放文件 *****
        initCss:[
        'style/forms/grid/grid1',
        'style/forms/grid/grid2',
        'style/forms/grid/grid3',
        'style/forms/template/tag',
        'style/forms/template/text',
        'style/forms/template/table',
        'style/forms/template/textArea',
        'style/forms/template/radioOption',
        'style/forms/template/date',
        'style/forms/template/button',
        'style/forms/template/uploadFile',
        'style/forms/template/richText',
        'style/forms/template/select',
        'style/forms/template/checkOption',
        'style/forms/template/dataLexi',
        'style/forms/template/uploadImg',
        'style/forms/template/selector',
        'style/forms/formDevise',
        'style/forms/dragLay',
        'style/forms/formPreview'
      ],
      // formAreaInfo:'.formPreview',
      formAreaInfo:'html',
      temDate:'.temDate',
      uploadFileBtn:'.uploadFileBtn',
      uploadImgBtn:'.uploadImgBtn',
      richTextArea:'.richTextArea',
      selectInput:'.selectInput',
      radioOptionCont:'.radioOptionCont',
      dataLexiTree:'.dataLexiTree',
      selectorBtn:'.selectorBtn',
    },
    temQuery = new propsHandle()  // 实例化模板功能部分
    ;



  // --- 通用方法 -----
    




// ------start---------


    // init 模板部分渲染
    ice.loadCss(defProps.initCss);

     // 数据加载 data解析
     $.ajax({
          url:  serverPath.formPath + setter.formLinkPath +'formDef/edit',
          type: "GET",
          contentType: 'application/json',
          dataType: 'json',
          data:{
            formDefId:formId
          },
          success: function(result) {
            if(result.data.formDef){
              var data = result.data.formDef;
              $('.formPreview').html(decodeURI(decodeURIComponent( data.html)));

                //根据当前登录人密级查询表单密级列表
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: serverPath.systemPath + setter.sysLinkPath + "dictionary/listFilterByUserSecret",
                    data: {'nodeKey': 'sjmj'},
                    success: function (result) {
                        $("select[name='fileLevel']").html("");
                        $.each(result.data, function (index, objVal) {
                            //业务数据密级下拉框重新赋值
                            $("select[name^='m:'][name$='dataPrivacyLevel']").append("<option value=" + objVal.itemValue + ">" + objVal.itemName + "</option>");
                        });
                        $("select[name^='m:'][name$='dataPrivacyLevel']").val(1);
                        //新增初始化附件上传控件密级下拉框
                        var dataPrivacyObj = $("select[name^='m:'][name$='dataPrivacyLevel']");
                        fileLevelVal(dataPrivacyObj);
                        form.render();

                        var dataPrivacyObj = $("select[name^='m:'][name$='dataPrivacyLevel']");
                        dataPrivacyObj.change(function(){
                            fileLevelVal(dataPrivacyObj);
                        })
                    }
                });
                //初始化组件事件
              temQuery.initTemEvent(defProps,serverPath,setter);
              form.render();
            }else{
              layer.msg(result.msg)
            }
          }
     });

    //  init部分默认执行方法
    // 初始化模板功能
    temQuery.initTem({
        selectorBtn:defProps.selectorBtn,
        selectorTemPath:setter.views+defProps.viewMould
    });

    // 子表初始化事件
    temQuery.initSubEvent(defProps,serverPath,setter);


        //业务数据密级和附件密级联动设置
        function fileLevelVal(obj){
            $("select[name='fileLevel']").html("");
            var privacyJson ={};
            $("select[name^='m:'][name$='dataPrivacyLevel'] option").each(function () {
                var privacyVal = $(this).val();
                var privacyText = $(this).text();
                privacyJson[privacyVal]=privacyText;
            });
            var selVal = obj.val();
            for(var j=1;j<=selVal;j++){
                $("select[name='fileLevel']").append("<option value=" + j + ">" + privacyJson[j] + "</option>");
            }
            form.render();
        }
  });

</script>
<style>
    #LAY_app{
        overflow: auto;
    }
    .layui-layer-content{
        height: 230px;
    }
</style>
</body>
</html>